import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { viteMockServe } from 'vite-plugin-mock';
import path from 'path';
import { svgBuilder } from './src/plugins/svgBuilder';

export default ({ command }) => {
    const prodMock = false;
    return defineConfig({
        plugins: [
            vue(),
            vueJsx({}),
            viteMockServe({
                localEnabled: command === 'serve' && prodMock,
                prodEnabled: command !== 'serve' && prodMock,
                injectCode: `
                import { setupProdMockServer } from '../mock/mockServe';
                setupProdMockServer();
            `
            }),
            svgBuilder('./src/icons/svg/')
        ],
        resolve: {
            alias: {
                '@': path.join(__dirname, 'src')
            }
        },
        css: {
            preprocessorOptions: {
                less: {
                    modifyVars: {
                        'primary-color': '#1890ff',
                        'link-color': '#1890ff',
                        'border-radius-base': '4px'
                    },
                    javascriptEnabled: true
                }
            }
        },
        server: {
            proxy: {
                // 选项写法
                '/qms': {
                    logLevel: 'debug',
                    // target: 'http://localhost:5000', // 本地
                    target: 'http://10.176.116.118:5000',
                    //  rewrite: path => path.replace(/^\/api/, ''), // 重写传过来的path路径，比如 `/api/index/1?id=10&name=zs`（注意:path路径最前面有斜杠（/），因此，正则匹配的时候不要忘了是斜杠（/）开头的；选项的 key 也是斜杠（/）开头的）
                    changeOrigin: true // true/false, Default: false - changes the origin of the host header to the target URL
                }
            }
        }
    });
};